<?php
/**
 * Installer DB data insertion page
 *
 * @copyright		The XOOPS project http://www.xoops.org/
 * @license			http://www.fsf.org/copyleft/gpl.html GNU General Public License (GPL)
 * @package			installer
 * @since			2.0.18
 * @version			$Id: page_tablesfill.php 605 2006-07-01 22:29:36Z skalpa $
 *
 * @author			Haruki Setoyama  <haruki@planewave.org>
 * @author			Kazumi Ono <webmaster@myweb.ne.jp>
 * @author			Skalpa Keo <skalpa@xoops.org>
 * @author			dugris <dugris@frxoops.org>
**/

require_once 'common.inc.php';
if ( !defined('XOOPS_INSTALL') ) { die('XOOPS Custom Installation die'); }

$wizard->setPage( 'tablesfill' );
$pageHasForm = false;
$pageHasHelp = false;

$vars =& $_SESSION['settings'];

include_once "../mainfile.php";
include_once './class/dbmanager.php';
$dbm =& new db_manager();

if ( !$dbm->isConnectable() ) {
	$wizard->redirectToPage( 'dbsettings' );
	exit();
}

$res = $dbm->query( "SELECT COUNT(*) FROM " . $dbm->db->prefix( "users" ) );
if ( !$res ) {
  	$wizard->redirectToPage( 'dbsettings' );
	exit();
}
list ( $count ) = $dbm->db->fetchRow( $res );
$process = $count ? '' : 'insert';

if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
	if ( !$process ) {
		$wizard->redirectToPage( '+0' );
		exit();
	}
	include_once './makedata.php';
	//include_once './class/cachemanager.php';
	//$cm = new cache_manager;
	$cm = 'dummy';

	$wizard->loadLangFile( 'install2' );

	extract( $_SESSION['siteconfig'], EXTR_SKIP );
	$language = $wizard->language;

  	$result = $dbm->queryFromFile('./sql/'.XOOPS_DB_TYPE.'.data.sql');
  	$result = $dbm->queryFromFile('./language/'.$language.'/'.XOOPS_DB_TYPE.'.lang.data.sql');
  	$group = make_groups( $dbm );

  	$result = make_data( $dbm, $cm, $adminname, $adminpass, $adminmail, $language, $group );
  	$content = $dbm->report();
} else {
	$msg = $process ? READY_INSERT_DATA : DATA_ALREADY_INSERTED;
	$pageHasForm = $process ? true : false;

	$content = "<div class='x2-note confirmMsg'>$msg</div>";
}

include 'install_tpl.php';

?>
